package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersCancelDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderDetailsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrdersAdminMapper {
/**订单搜索*/
    Page<OrderDetailsVO> OrderPage(LocalDateTime beginTime, LocalDateTime endTime, Integer status, String phone, String number);

    /**带派送状态数量 status = 3 */
    @Select("select count(*) from orders where status = 3")
    Integer queryStatConfirmedNum();

    /**派送中状态status = 4*/
    @Select("select count(*) from orders where status = 4")
    Integer queryStatDeliveryInProgressNum();

    /**待接单数量status = 2*/
    @Select("select count(*) from orders where status = 2")
    Integer queryStatToBeConfirmedNum();

    /**取消订单*/

    void updateCancelOrderMS(String cancelReason,Long id,LocalDateTime cancelTime);

    /**将订单状态改变*/
    @Update(" update orders set status = 6 where id = #{id}")
    void upateOrderStatus(Long id);

    /**查询需要取消订单的状态*/
    @Select("select count(*) from orders where status = 3 or status = 4 and id = #{id}")
    Integer queryCancelStatus(OrdersCancelDTO ordersCancelDTO);

    /**查询拒订单的状态*/
    @Select("select count(*) from orders where status = 2 and id = #{id}")
    Integer queryRejectStatus(Long id);

    /**完成订单*/
    @Update(" update orders set status = 5,delivery_time = #{deliveryTime} where id = #{id}")
    void upateOrdercompleteStatus(Long id,LocalDateTime deliveryTime);

    /**改变拒绝订单状态*/
    @Update(" update orders set status = 7 where id = #{id}")
    void upateOrderRejectionStatus(Long id);

    /**接受订单*/
    @Update(" update orders set status = 3 where id = #{id}")
    void upateOrderconfirmStatus(Long id);

    /**查询订单状态*/
    @Select(" select count(*) from orders where status = #{status} and id = #{id}")
    Integer queryOrderStatus(long id,Integer status);

    /**订单派送*/
    @Update(" update orders set status = 4 where id = #{id}")
    void deliveryOrder(Integer id);

/**查询所有未付款的订单*/
    @Select("select * from orders where status = 1")
    List<Orders> QueryNoPayOrder();

/**查询超时派送订单*/
@Select("SELECT * FROM orders where status = #{status} and estimated_delivery_time < #{estimatedDeliveryTime}")
    List<Orders> QueryDeliveryPassOrder(LocalDateTime estimatedDeliveryTime, Integer status);
/**拒单*/
    void updateRejectionOrderMS(String rejectionReason, Long id, LocalDateTime now);
}
